#ifndef APP_TERRAIN_HPP_
#define APP_TERRAIN_HPP_

#include <device/aerProgram.hpp>
#include <device/aerTexture.hpp>
#include <view/aerCamera.hpp>
#include <misc/aerHeightmap.hpp>
#include <aerMesh.hpp>

#include "Grass.hpp"



class Terrain
{
  private:
    enum TextureMaterial
    {
      TEX_SAND = 0,
      TEX_ROCK,
      TEX_GRASS,
      TEX_SLOPE,
      TEX_NORMALMAP0,
      TEX_NORMALMAP1,
      TEX_NORMALMAP2,
      
      kNumTextureMaterial
    };
    
    
  private:
    aer::Program  m_program;          // Terrain's program with tesselation
    aer::Mesh     m_mesh;             // Terrain's patch mesh
    aer::Texture  m_attribTex;        // RGBA texture (RGB:normal, A:height)
    aer::Texture  m_materialTex[kNumTextureMaterial];
    
    aer::Heightmap m_heightmap;    
    Grass m_grass;
    
    // Properties
    unsigned int m_vertexPerLines;
    unsigned int m_patchPerLines;
    float m_patchSize;
    float m_geometryScale;
    bool m_bUseDynamicLOD;
    
    
    
  public:
    Terrain();
    ~Terrain();
    
    void init();    
    void render(const aer::Camera &camera);//
    
    
  private:
    void initHeightmap();
    void initGeometry();
    void initTexture();
    void initShader();
};

#endif // APP_TERRAIN_HPP_
